<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
     class Emiter{
         constructor()
         {
             this.events = {};
         }

         on(eventName,cb)
         {
            if(!this.events[eventName])
            {
                this.events[eventName] = [];
            }
            this.events[eventName].push(cb);
         }

         emit(eventName,...args)
         {
             if(!this.events[eventName])
             {
                 return;
             }
             this.events[eventName].forEach((item)=>{
                 item(...args);
             })
         }

         off(eventName,cb)
         {
             if(!this.events[eventName])
             {
               return;
             }

             this.events[eventName] = this.events[eventName].filter(item=>{ return
              item!=cb;
             })
         }
     }

     let emiter = new Emiter();
     function fn()
     {
        console.log('message');
     }
     emiter.on('message',fn);
     emiter.emit('message');
     emiter.off('message',fn);
     emiter.emit('message');
    </script>
</body>
</html>